<script type="text/javascript">
    var check_submit = 0;
    
    $(document).ready(function(){
        check_code('no');
        $('form.form').submit(function(){
            $("#temp-submit").addClass('hidden');
            $("form.form input[type=submit]").removeClass("hidden");
            if(!$("#type").val()){
                alert("Please select the voucher or gift card");
                return false;
            }
            if(!$("#amount").val()){
                alert("Please input amount of the payment");
                return false;
            }
            
            $("#temp-submit").removeClass('hidden');
            $("form.form input[type=submit]").addClass("hidden");
            return true;
        });
    });
    function check_code(type){
        if(!$("#code").val()&&type=="yes"){
            alert("Please input code!");
        }else if(!$("#code").val()&&type=="no"){
            
        }else{
            url = "<?php echo $this->Html->url(array('controller'=>'cashiers','action'=>'check_code')) ?>/"+$("#code").val();
            $.get(url, function(data){
                $("#sell").removeClass("hidden");
                $('#content_type').html(data);
            });
        }
        return false;
    }
    function select_cart(type,id){
        if(type=="gift"){
            $('#type').val('gift');
            $('#voucher_id').val('0');
            $('#gift_id').val(id);
        }else if(type=="voucher"){
            $('#type').val('voucher');
            $('#voucher_id').val(id);
            $('#gift_id').val(0);
        }
        $('.card').each(function(){
            $(this).removeClass('selected_card');
        });
        $('#'+type+"_"+id).addClass("selected_card");
        return false;
    }
</script>
<style type="text/css">
    .card{
        padding: 10px;
        margin: 15px;
        border: 1px solid #CCC;
    }
    .card li{
        list-style: none;
        display: inline-block;
        width: 150px;
        padding: 10px;
    }
    #content_type{
        padding: 20px !important;
        border: 1px solid #CCC;
    }
    .expired{
        color: red;
    }
    .selected_card{
        background: #F8E3EC;
    }
</style>
<div id="content-outer">
  <div id="content">
    <div id="page-heading"><h1>Selling Gift card / Voucher </h1></div>
    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
        <tr>
            <th rowspan="3" class="sized">
                <?php //echo $this->Html->image('../images/shared/side_shadowleft.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
            </th>
            <th class="topleft"></th>
            <td id="tbl-border-top">&nbsp;</td>
            <th class="topright"></th>
            <th rowspan="3" class="sized">
                <?php //echo $this->Html->image('../images/shared/side_shadowright.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
             </th>
        </tr>
        <tr>
            <td id="tbl-border-left"></td>
            <td>
                <div id="content-table-inner">
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr valign="top">
                            <td>
                                <?php echo $this->Form->create("CashierSell", array('url'=>array('controller'=>'cashiers','action' => 'sell'), 'class' => 'form', 'type' => 'file')); ?>
                                <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                    <?php
                                        echo $this->Session->flash();
                                        echo $this->Form->input('type',array('id'=>'type','type'=>'hidden'));
                                        echo $this->Form->input('voucher_id',array('id'=>'voucher_id','type'=>'hidden'));
                                        echo $this->Form->input('gift_id',array('id'=>'gift_id','type'=>'hidden'));
                                    ?>
                                    <tr>
                    			 <th valign="top">Code :</th>
                    			 <td>
                                        <?php 
                                            echo $this->Form->input('code', array('id'=>"code",'label' => false,'div' => false, 'class' => 'inp-form'));
                                        ?> 
                                        <a href="#" onclick="return check_code('yes')" class="button">Check code</a>
                                        </td>
                                        <td></td>
                                    </tr>
                                    <tr id="sell" class="hidden">
                                        <td colspan="3" id="content_type">
                                        </td>
                                    </tr>
                                    <tr><td colspan="3">&nbsp;</td></tr>
                                    <tr>
                    			 <th valign="top">Amount payment :</th>
                    			 <td>
                                        <?php 
                                            echo $this->Form->input('amount', array('id'=>"amount",'label' => false,'div' => false, 'class' => 'inp-form'));
                                        ?> 
                                        </td>
                                        <td></td>
                                    </tr>
                                    <tr><td colspan="3">&nbsp;</td></tr>
                                    <tr>
                                        <th>&nbsp;</th>
                                        <td valign="top">
                                            <?php echo $this->Form->submit('Save', array('class' => 'submit-button','label'=>false,'div'=>false)); ?>
                                            <?php echo $this->Html->link('Cancel', array('controller' => $lN, 'action' => 'index', 'admin' => false), array('class' => 'cancel-button')); ?>
                                        </td>
                                        <td></td>
                                    </tr>
                                </table>
                                <?php echo $this->Form->end();?>
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                               <?php echo $this->Html->image('../images/shared/blank.gif', array('alt' => 'blank', 'width' => '695', 'height' => '1')); ?>
                            </td>
                            <td></td>
                        </tr>
                    </table>
                    <div class="clear"></div>
                </div>
            </td>
            <td id="tbl-border-right"></td>
        </tr>
        <tr>
            <th class="sized bottomleft"></th>
            <td id="tbl-border-bottom">&nbsp;</td>
            <th class="sized bottomright"></th>
        </tr>
    </table>
    <div class="clear">&nbsp;</div>
  </div>
</div>